package com.kits.store.core

import android.os.Environment
import java.io.File

object Utils {
    /**
     * 调试使用，展示某个路径下所有的文件
     */
    fun showFileList(path:String){
        val current = File(path)
        if (current.isDirectory){
            val fileList = current.listFiles()
            fileList?.forEach {
                showFileList(it.absolutePath)
            }
        }else{
            println("file : $path")
        }
    }


    fun createFile(basePath:String?,dir:String?,file:String):File?{
        var targetPath:String? = null
        if (basePath == null){
            return null
        }
        if (dir == null){
            targetPath = basePath + File.separator + file
        }else{
            val targetDir = File(basePath +File.separator + dir)
            if(targetDir.exists() || targetDir.mkdirs()){
                targetPath = basePath +File.separator + dir + File.separator + file
            }
        }
        if (targetPath == null){
            return null
        }
        return File(targetPath)
    }

    fun checkExternalMount():Boolean{
        if (Environment.MEDIA_MOUNTED == Environment.getExternalStorageState()){
            return true
        }
        return false
    }
}